package examples.fxroot

import de.saxsys.mvvmfx.FluentViewLoader
import de.saxsys.mvvmfx.FxmlView
import de.saxsys.mvvmfx.InjectViewModel
import de.saxsys.mvvmfx.utils.listener.ICleanable
import javafx.fxml.FXML
import javafx.fxml.Initializable
import javafx.scene.control.Button
import javafx.scene.control.Label
import javafx.scene.control.TextField
import javafx.scene.layout.HBox

/**
 * Created by TK-chenbin on 2015/6/5.
 */
class LabeledTextField extends HBox implements FxmlView<LabeledTextFieldViewModel>,
        Initializable, ICleanable {
    @FXML
    private Label label
    @FXML
    private TextField textField
    @FXML
    private Button button

    @InjectViewModel
    private LabeledTextFieldViewModel viewModel

    public LabeledTextField() {
        FluentViewLoader.fxmlView(LabeledTextField)
                .root(this).codeBehind(this).load()
    }

    @Override
    void initialize(URL location, ResourceBundle resources) {
        label.textProperty().bind(viewModel.labelText())
        textField.textProperty().bindBidirectional(viewModel.inputText())

        button.disableProperty().bind(viewModel.buttonDisabled())
    }

    @FXML
    void onAction() {
        viewModel.changeLabel()
    }

    @Override
    void clean() {

    }
}
